-
Notifications
You must be signed in to change notification settings - Fork 0
Session-based funnel conversion examples (UTM source/medium) #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
📝 WalkthroughWalkthroughThe pull request updates data activation documentation and SQL templates to clarify analytical approaches. One model description is enhanced to emphasize event-level aggregation and event-based metrics, while SQL query templates are comprehensively revised to shift from event-based to session-based funnel calculations, including metrics for daily funnels, top pages, and UTM source analysis. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
data-activation/template-resources/sql-query-library.mdx (1)
1464-1477:⚠️ Potential issue | 🟡 MinorRename alias
foto satisfy codespellCI is failing on Line 1466 due to the
foalias. Rename the alias to avoid the codespell false positive.🔧 Proposed fix
- FROM first_valid_orders fo + FROM first_valid_orders first_orders LEFT JOIN `your_project.sm_transformed_v2.obt_orders` o - ON o.sm_customer_key = fo.sm_customer_key + ON o.sm_customer_key = first_orders.sm_customer_key AND o.is_order_sm_valid = TRUE AND o.order_cancelled_at IS NULL AND o.order_net_revenue > 0 - AND o.order_processed_at_local_datetime > fo.first_order_at_local_datetime - AND o.order_processed_at_local_datetime < DATETIME_ADD(fo.first_order_at_local_datetime, INTERVAL 90 DAY) + AND o.order_processed_at_local_datetime > first_orders.first_order_at_local_datetime + AND o.order_processed_at_local_datetime < DATETIME_ADD(first_orders.first_order_at_local_datetime, INTERVAL 90 DAY) GROUP BY 1, 2
🤖 Fix all issues with AI agents
In `@data-activation/template-resources/sql-query-library.mdx`:
- Around line 363-374: The query in the session_daily aggregation selects date
plus aggregate expressions (aliases sessions, sessions_with_view_item,
view_to_cart_rate, etc.) but lacks a GROUP BY, causing BigQuery to fail; update
the SQL in the session_daily query block to add a GROUP BY date (grouping by the
selected date column) before the ORDER BY date so the aggregates are computed
per date.
| date, | ||
| view_item_events, | ||
| add_to_cart_events, | ||
| begin_checkout_events, | ||
| purchase_events, | ||
| event_order_revenue, | ||
| SAFE_DIVIDE(add_to_cart_events, NULLIF(view_item_events, 0)) AS add_to_cart_per_view_item, | ||
| SAFE_DIVIDE(begin_checkout_events, NULLIF(add_to_cart_events, 0)) AS begin_checkout_per_add_to_cart, | ||
| SAFE_DIVIDE(purchase_events, NULLIF(begin_checkout_events, 0)) AS purchase_per_begin_checkout, | ||
| SAFE_DIVIDE(purchase_events, NULLIF(view_item_events, 0)) AS purchase_per_view_item | ||
| FROM daily | ||
| COUNT(*) AS sessions, | ||
| SUM(has_view_item) AS sessions_with_view_item, | ||
| SUM(has_add_to_cart) AS sessions_with_add_to_cart, | ||
| SUM(has_begin_checkout) AS sessions_with_begin_checkout, | ||
| SUM(has_purchase) AS sessions_with_purchase, | ||
| SAFE_DIVIDE(SUM(has_add_to_cart), NULLIF(SUM(has_view_item), 0)) AS view_to_cart_rate, | ||
| SAFE_DIVIDE(SUM(has_begin_checkout), NULLIF(SUM(has_add_to_cart), 0)) AS cart_to_checkout_rate, | ||
| SAFE_DIVIDE(SUM(has_purchase), NULLIF(SUM(has_begin_checkout), 0)) AS checkout_to_purchase_rate, | ||
| SAFE_DIVIDE(SUM(has_purchase), NULLIF(COUNT(*), 0)) AS session_conversion_rate | ||
| FROM session_daily | ||
| ORDER BY date; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add missing GROUP BY for daily funnel aggregates
Line 363 selects date alongside aggregates without a GROUP BY, which will fail in BigQuery.
🔧 Proposed fix
SELECT
date,
COUNT(*) AS sessions,
SUM(has_view_item) AS sessions_with_view_item,
SUM(has_add_to_cart) AS sessions_with_add_to_cart,
SUM(has_begin_checkout) AS sessions_with_begin_checkout,
SUM(has_purchase) AS sessions_with_purchase,
SAFE_DIVIDE(SUM(has_add_to_cart), NULLIF(SUM(has_view_item), 0)) AS view_to_cart_rate,
SAFE_DIVIDE(SUM(has_begin_checkout), NULLIF(SUM(has_add_to_cart), 0)) AS cart_to_checkout_rate,
SAFE_DIVIDE(SUM(has_purchase), NULLIF(SUM(has_begin_checkout), 0)) AS checkout_to_purchase_rate,
SAFE_DIVIDE(SUM(has_purchase), NULLIF(COUNT(*), 0)) AS session_conversion_rate
FROM session_daily
+GROUP BY date
ORDER BY date;📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| date, | |
| view_item_events, | |
| add_to_cart_events, | |
| begin_checkout_events, | |
| purchase_events, | |
| event_order_revenue, | |
| SAFE_DIVIDE(add_to_cart_events, NULLIF(view_item_events, 0)) AS add_to_cart_per_view_item, | |
| SAFE_DIVIDE(begin_checkout_events, NULLIF(add_to_cart_events, 0)) AS begin_checkout_per_add_to_cart, | |
| SAFE_DIVIDE(purchase_events, NULLIF(begin_checkout_events, 0)) AS purchase_per_begin_checkout, | |
| SAFE_DIVIDE(purchase_events, NULLIF(view_item_events, 0)) AS purchase_per_view_item | |
| FROM daily | |
| COUNT(*) AS sessions, | |
| SUM(has_view_item) AS sessions_with_view_item, | |
| SUM(has_add_to_cart) AS sessions_with_add_to_cart, | |
| SUM(has_begin_checkout) AS sessions_with_begin_checkout, | |
| SUM(has_purchase) AS sessions_with_purchase, | |
| SAFE_DIVIDE(SUM(has_add_to_cart), NULLIF(SUM(has_view_item), 0)) AS view_to_cart_rate, | |
| SAFE_DIVIDE(SUM(has_begin_checkout), NULLIF(SUM(has_add_to_cart), 0)) AS cart_to_checkout_rate, | |
| SAFE_DIVIDE(SUM(has_purchase), NULLIF(SUM(has_begin_checkout), 0)) AS checkout_to_purchase_rate, | |
| SAFE_DIVIDE(SUM(has_purchase), NULLIF(COUNT(*), 0)) AS session_conversion_rate | |
| FROM session_daily | |
| ORDER BY date; | |
| date, | |
| COUNT(*) AS sessions, | |
| SUM(has_view_item) AS sessions_with_view_item, | |
| SUM(has_add_to_cart) AS sessions_with_add_to_cart, | |
| SUM(has_begin_checkout) AS sessions_with_begin_checkout, | |
| SUM(has_purchase) AS sessions_with_purchase, | |
| SAFE_DIVIDE(SUM(has_add_to_cart), NULLIF(SUM(has_view_item), 0)) AS view_to_cart_rate, | |
| SAFE_DIVIDE(SUM(has_begin_checkout), NULLIF(SUM(has_add_to_cart), 0)) AS cart_to_checkout_rate, | |
| SAFE_DIVIDE(SUM(has_purchase), NULLIF(SUM(has_begin_checkout), 0)) AS checkout_to_purchase_rate, | |
| SAFE_DIVIDE(SUM(has_purchase), NULLIF(COUNT(*), 0)) AS session_conversion_rate | |
| FROM session_daily | |
| GROUP BY date | |
| ORDER BY date; |
🤖 Prompt for AI Agents
In `@data-activation/template-resources/sql-query-library.mdx` around lines 363 -
374, The query in the session_daily aggregation selects date plus aggregate
expressions (aliases sessions, sessions_with_view_item, view_to_cart_rate, etc.)
but lacks a GROUP BY, causing BigQuery to fail; update the SQL in the
session_daily query block to add a GROUP BY date (grouping by the selected date
column) before the ORDER BY date so the aggregates are computed per date.
Fixes misleading event-based funnel conversion examples in SQL Query Library.
sm_transformed_v2.obt_funnel_event_history(distinct-session denominators).rpt_funnel_events_performance_hourlytable doc to clearly state it is event-aggregated and ratios are directional, not true conversion.Goal: Mintlify retrieval should stop suggesting event-count ratios as “conversion rate”.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.